package com.tt.dp.proxy.javaimpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class NonOwnerInvocationHandler implements InvocationHandler {

    private PersonBean personBean;

    public NonOwnerInvocationHandler(PersonBean personBean) {
        this.personBean = personBean;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws IllegalAccessException {

        try {
            if(method.getName().startsWith("get")){
                return method.invoke(proxy,args);
            }else if(method.getName().startsWith("setHotOrNotRating")){
                return method.invoke(proxy,args);
            }else if(method.getName().startsWith("set")){
                throw new IllegalAccessException();
            }
        }catch (InvocationTargetException ex){
            ex.printStackTrace();
        }

        return null;
    }
}
